from flask import Flask, render_template, redirect, request, jsonify, make_response

app = Flask(__name__)


@app.route('/index', methods=['GET', 'POST'])
def index():
    # 请求相关
    # request.method   方法名
    # request.args     参数
    # request.form
    # request.cookies  cookies
    # request.headers  请求头
    # request.path     请求路径
    # request.files    获取上传文件
    # obj = request.files['the_file_name']  # 得到上传文件名
    # obj.save('/var/www/uploads/' + secure_filename(obj.filename))  保存到本地

    # request.values
    # request.full_path
    # request.script_root
    # request.url
    # request.base_url
    # request.url_root
    # request.host_url
    # request.host

    # 响应相关
    return ""  # 字符串
    return json.dumps({})  # 字典
    return jsonify({})   # 内置模块自动转成字典
    return render_template('index.html', n1=123)  # 模板
    return redirect('/index')  # 重定向

    # response = make_response(render_template('index.html'))  # 设置返回的cookie，headers等
    # response = make_response("xxxx")
    # response.set_cookie('key', 'value')
    # response.headers['X-Something'] = 'A value'
    # response.delete_cookie('key')
    # return response


if __name__ == '__main__':
    app.run()
